import type { Preset, SourceCodeTransformer } from "unocss"
import { defineConfig, presetAttributify } from "unocss"

import { presetApplet, presetRemRpx, transformerAttributify } from "unocss-applet"

// uni-app，mp-开头的平台为小程序
const isApplet = process.env?.UNI_PLATFORM?.startsWith("mp-") ?? false
// console.log(process.env?.UNI_PLATFORM);

const presets: Preset[] = []
const transformers: SourceCodeTransformer[] = []

if (isApplet) {
  presets.push(presetApplet())
  presets.push(presetRemRpx())
  transformers.push(transformerAttributify({ ignoreAttributes: ["block"] }))
} else {
  presets.push(presetApplet())
  presets.push(presetAttributify())
  // h5模式，将rpx转换为rem
  presets.push(presetRemRpx({ mode: "rpx2rem" }))
}

const primaryColorHex = '1296db'
const secondaryColorHex = 'fde3e1'
export default defineConfig({
  presets: [
    // ...
    ...presets
  ],
  rules: [],
  transformers: [
    // ...
    ...transformers
  ],
  shortcuts: {
    'text-primary': `text-hex-${primaryColorHex}`,
    'text-secondary': `text-hex-${secondaryColorHex}`,
    'bg-primary': `bg-hex-${primaryColorHex}`,
    'bg-secondary': `bg-hex-${secondaryColorHex}`,
    'border-primary': `border-hex-${primaryColorHex}`,
    'border-secondary': `border-hex-${secondaryColorHex}`,
    'text-black': 'text-hex-333333',
    'wh-full': 'w-full h-full',
    'flex-column': 'flex flex-col',
    'flex-center': 'justify-center items-center',
    'mx-center': 'mx-auto my-0'
  },
})

